package org.deschutter.dump;

import org.deschutter.Constants;
import org.deschutter.URLReader;
import org.deschutter.Queries;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.net.MalformedURLException;

/**
 * User: Berten De Schutter
 * Date: 08-Jul-2009
 * Time: 21:04:05
 */
public class StatsDump implements Constants/*, Job*/ {
    //public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
      
      public static void main(String[] args) throws Exception {
       Pattern compiledRegex;
        Matcher regexMatcher;

        String statspage = null;
        try {
            statspage = URLReader.get(STATS_PAGE);
        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }
        // Get Fleets
          String oi = "<tr class=\"(Ter|Cat|Xan|Zik|Etd)\">.+?>([^<]+)</td>"

                           + "<td>(\\w+)</td>"
                           + "(?:<td>(\\w\\w|\\-)</td>)?"
                           + "(?:<td>(\\w\\w|\\-)</td>)?"
                           + "(?:<td>(\\w\\w|\\-)</td>)?"
                           + "<td>(\\w+)</td>"
                           + ".+?(\\d+|\\-)</td>"
         + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?(\\d+|\\-)</td>"
                           + ".+?</tr>";

        //compiledRegex = Pattern.compile("<tr class=\"(Ter|Cath|Xan|Zik|Etd)\">.+?>([^<]+)</td><td>(\\w+)</td><td>(\\w\\w|\\-)</td><td>(\\w\\w|\\-)</td><td>(\\w\\w|\\-)</td><td class=\"center\">(\\w+)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?(\\d+|\\-)</td>.+?</tr>");
        compiledRegex = Pattern.compile(oi);

          
          regexMatcher = compiledRegex.matcher(statspage);

        while (regexMatcher.find()) {
            Queries.addShipStat(regexMatcher.group(1),regexMatcher.group(2),regexMatcher.group(3),regexMatcher.group(4),regexMatcher.group(5),regexMatcher.group(6),regexMatcher.group(7),regexMatcher.group(8),regexMatcher.group(9),regexMatcher.group(10),regexMatcher.group(11),regexMatcher.group(12),regexMatcher.group(13),regexMatcher.group(14),regexMatcher.group(15));
        }
    }
}
